#include "optionswidget.h"
#include "filetable.h"
#include "slepui.h"


void OptionsWidget::createReguarizationParameterOptions(){
    QLayout *layout = new QVBoxLayout(this);
    QWidget *regularizationOptionsWidget = new QWidget(this);
    regularizationOptionsWidget->setLayout(layout);
    tabWidget->addTab(regularizationOptionsWidget,tr("Regularization"));
    regularizationOptions = new QGroupBox(tr("Regularization parameters"), this);

    QGridLayout *regularizationLayout = new QGridLayout;
    buttonGroupRFlag = new QButtonGroup(this);
	if(method==Method_Least_R || method==Method_nnLeast_R || method==Method_Logistic_R || method==Method_nnLogistic_R 
		|| method == Method_glLeast_R || method == Method_glLogistic_R || method == Method_mtLeast_R){
		labelRFlag = new QLabel(tr("Regularization option:"), this);
		buttonGroupRFlag->addButton(new QRadioButton(tr("lambda = input value")),0);
		buttonGroupRFlag->addButton(new QRadioButton(tr("lambda = lambda_max * lambda")),1);
		(buttonGroupRFlag->button(1))->setChecked(true);
		opts->rFlag = 1;
		regularizationLayout->addWidget(labelRFlag,0,0,2,1,Qt::AlignTop|Qt::AlignLeft);
		regularizationLayout->addWidget(buttonGroupRFlag->button(0),0,1,Qt::AlignLeft);
		regularizationLayout->addWidget(buttonGroupRFlag->button(1),1,1,Qt::AlignLeft);
	}
    regularizationOptions->setLayout(regularizationLayout);

    spinBoxRsL2 = new QDoubleSpinBox(this);
    spinBoxRsL1 = new QDoubleSpinBox(this);
    regularizationLayout->addWidget(new QLabel(tr("L2 Regularization parameter :"),this),2,0,Qt::AlignLeft);
    regularizationLayout->addWidget(spinBoxRsL2,2,1,Qt::AlignCenter);
    spinBoxRsL2->setRange(0.0,1.0);
    spinBoxRsL2->setSingleStep(0.001);
    spinBoxRsL2->setValue(0.000);
	spinBoxRsL2->setDecimals(3);
	setOPTS_rsL2(0.0);

	if(method==Method_Least_R || method==Method_nnLeast_R || method==Method_Logistic_R || method==Method_nnLogistic_R || method == Method_glLeast_R || method == Method_glLogistic_R){
		regularizationLayout->addWidget(new QLabel(tr("L1 Regularization <b>parameter</b> :"),this),3,0,Qt::AlignLeft);
		regularizationLayout->addWidget(spinBoxRsL1,3,1,Qt::AlignCenter);
		spinBoxRsL1->setRange(0.0,1.0);
		spinBoxRsL1->setSingleStep(0.001);
		spinBoxRsL1->setValue(0.2);
		spinBoxRsL1->setDecimals(3);
	} else if(method==Method_Least_C || method==Method_nnLeast_C || method==Method_Logistic_C || method==Method_nnLogistic_C ){
		regularizationLayout->addWidget(new QLabel(tr("L1 ball <b>constraint</b> :"),this),3,0,Qt::AlignLeft);
		regularizationLayout->addWidget(spinBoxRsL1,3,1,Qt::AlignCenter);
		spinBoxRsL1->setRange(0.0,10000.0);
		spinBoxRsL1->setSingleStep(1.0);
		spinBoxRsL1->setValue(100.0);
		spinBoxRsL1->setDecimals(2);
	} else if(method==Method_mtLeast_R){
		regularizationLayout->addWidget(new QLabel(tr("L1 Regularization <b>parameter</b> :"),this),3,0,Qt::AlignLeft);
		regularizationLayout->addWidget(spinBoxRsL1,3,1,Qt::AlignCenter);
		spinBoxRsL1->setRange(0.0,10000.0);
		spinBoxRsL1->setSingleStep(1.0);
		spinBoxRsL1->setValue(0.5);
		spinBoxRsL1->setDecimals(2);
	}

    layout->addWidget(regularizationOptions);
    ((QBoxLayout*)layout)->addStretch();
}